using UnityEngine;
using UnityEngine.UI;

public class EE_UI_BuildingOptions : MonoBehaviour
{
    private static EE_UI_BuildingOptions instance = null; public static EE_UI_BuildingOptions Instance {get{return instance;}}
    
    [SerializeField] public GameObject elements = null;
    
    private Button buttonInfo = null; public Button ButtonInfo { get {return buttonInfo;} }
    private Button buttonRotate = null; public Button ButtonRotate { get {return buttonRotate;} }
    private Button buttonUpgrade = null; public Button ButtonUpgrade { get {return buttonUpgrade;} }

    private void Awake()
    {
        instance = this;
        elements.SetActive(false);
        Transform buttonsPanel = elements.transform.GetChild(0).transform.GetChild(0).transform.GetChild(0).transform;
        buttonInfo = buttonsPanel.GetChild(0).GetComponent<Button>();
        buttonRotate = buttonsPanel.GetChild(1).GetComponent<Button>();
        buttonUpgrade = buttonsPanel.GetChild(2).GetComponent<Button>();
    }

    private void Start()
    {
        buttonInfo.onClick.AddListener(OnInfoClick);
        buttonRotate.onClick.AddListener(OnRotateClick);
        buttonUpgrade.onClick.AddListener(OnUpgradeClick);
    }

    private void OnInfoClick()
    {
        Debug.Log("OnInfoClick");
    }

    private void OnRotateClick()
    {
        Debug.Log("OnRotateClick");
        // 需要 *= 实现增量旋转，否则 = 只是固定住朝向
        EE_Building_Controller.Instance.transform.localRotation *= Quaternion.Euler(0, 90, 0);
    }

    private void OnUpgradeClick()
    {
        Debug.Log("OnUpgradeClick");
        EE_UI_Upgrade.Instance.elements.SetActive(true);
    }

    public void SetStatus(bool status)
    {
        if (EE_Building_Controller.Instance != null && EE_Building_Controller.Instance.data.constructing)
        {
            // 正在升级的建筑 不能显示 选项板
            elements.SetActive(false);
        }
        else
        {
            elements.SetActive(status);
        }
    }
}